package com.tourism.controller;

import com.tourism.common.Result;
import com.tourism.entity.FoodOrder;
import com.tourism.service.FoodOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/admin/foodOrder")
@CrossOrigin
public class FoodOrderController {

    @Autowired
    private FoodOrderService foodOrderService;

    @GetMapping("/list")
    public Result getOrderList(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(required = false) String userName,
            @RequestParam(required = false) String foodName) {
        System.out.println("\n\n\n\\n\n\n\n\n"+foodOrderService.getOrderList(page, pageSize, userName, foodName)+"\n\n\n\n\n\n\n");
        return foodOrderService.getOrderList(page, pageSize, userName, foodName);
    }

    @GetMapping("/{id}")
    public Result getOrderById(@PathVariable Integer id) {
        return foodOrderService.getOrderById(id);
    }

    @PostMapping("/add")
    public Result addOrder(@RequestBody FoodOrder foodOrder) {
        return foodOrderService.addOrder(foodOrder);
    }

    @PutMapping("/update")
    public Result updateOrder(@RequestBody FoodOrder foodOrder) {
        return foodOrderService.updateOrder(foodOrder);
    }

    @DeleteMapping("/delete/{id}")
    public Result deleteOrder(@PathVariable Integer id) {
        return foodOrderService.deleteOrder(id);
    }

    @PostMapping("/batch") // 修改为 @PostMapping
    public Result batchDeleteOrders(@RequestBody List<Integer> ids) {
        return foodOrderService.batchDeleteOrders(ids);
    }

    @GetMapping("/all")
    public Result getAllOrders() {
        return foodOrderService.getAllOrders();
    }
}
